﻿using System;
using System.Web.Mvc;
using BG.DAL.Model;
using BG.DAL.SQLDAL;
using BG.Admin.ViewModels;

namespace BG.Web.Areas.Admin.Controllers
{
    //[Authorize(Roles = "Admin, SuperUser")]
    [Authorize(Roles = "Admin")]
    public class CompanyController : Controller
    {

        public ViewResult Index()
        {
            int currentPage = 1;
            int pageSize = 10;

            ViewData["currentPage"] = currentPage;
            ViewData["pageSize"] = pageSize;

            return Index(currentPage, pageSize, null);
        }

        [HttpPost]
        public ViewResult Index(int? currentPage, int? pageSize, string gridAction)
        {
            var items = CompanyManager.GetAll();

            AdminViewModel model = new AdminViewModel();
            model.Companies = items;
            return View(model);
        }


        public ViewResult Details(Guid id)
        {
            return View();
        }

        public ActionResult Create()
        {
            return View();
        } 

        [HttpPost]
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
               
                return RedirectToAction("Index");  
            }

            return View();
        }
        
        public ActionResult Edit(Guid id)
        {
            return View();
        }

        [HttpPost]
        public ActionResult Edit(Company company)
        {
            if (ModelState.IsValid)
            {
                return RedirectToAction("Index");
            }
            return View();
        }

        public ActionResult Delete(Guid id)
        {
            return View();
        }

      
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(Guid id)
        {            
            return RedirectToAction("Index");
        }
    }
}